import 'package:flutter/material.dart';

import 'CalcKeyBoard.dart';

class KeyBoardButton extends StatefulWidget {

  final String name;
  final Color color;
  final bool bold;
  final bool enabled;
  final KeyboardClickCallback onTap;

  const KeyBoardButton({Key key, this.name, this.color, this.bold = false, this.enabled = true, this.onTap}) : super(key: key);

  @override
  _KeyBoardButtonState createState() => _KeyBoardButtonState();
}

class _KeyBoardButtonState extends State<KeyBoardButton> {

  bool _isTouch = false;

  @override
  Widget build(BuildContext context) {
    if (!widget.enabled) {
      return Container();
    }
    return GestureDetector(
      child: Container(
        margin: EdgeInsets.all(3),
        alignment: Alignment.center,
        decoration: BoxDecoration(
            shape: BoxShape.circle,
            color: _isTouch ? Colors.grey[100] : Colors.transparent
        ),
        child: Text(
          widget.name,
          style: TextStyle(
            fontSize: 20,
            color: widget.color ?? Color(0xff1A1A1A),
            fontWeight: widget.bold ? FontWeight.w700 : FontWeight.w400,
          ),
        ),
      ),
      onTapDown: (details) => _reset(true),
      onTapUp: (details) => _reset(false),
      onTapCancel: () => _reset(false),
      onTap: () => widget.onTap(widget.name)
    );
  }

  _reset(bool isTouch) {
    setState(() {
      _isTouch = isTouch;
    });
  }
}
